/*
 * Project Name: jmax
 * File Name: WiegandUtil.java
 * Copyright: Copyright(C) 1985-2015 ZKTeco Inc. All rights reserved.
 */
package com.xdtech.hotel.protocol.util;

import java.math.BigInteger;

/**
 * 韦根操作工具类
 * 
 * @author <a href="max.zheng@zkteco.com">郑志雄</>
 * @version TODO 添加版本
 * @see 相关类或方法，不需要请删除此行
 * @since 2015-5-7 上午11:49:51
 */
public class WiegandUtils
{
	public static String getCardByWg26(String data) {
		String cutData = data.substring(1, data.length()-1);
		//转十进制
		BigInteger ten = new BigInteger(cutData, 2);//转换为BigInteger类型
		return ten.toString();
	}
	
	public static String setCardToWg26(String data) {
		BigInteger src = new BigInteger(data);//转换为BigInteger类型
		String twoData = src.toString(2);//转换为2进制并输出结果
		return "0"+twoData+"0";
	}
	
	public static void main(String[] args)
	{
		//00110001110010101100011000
		System.out.println(getCardByWg26("00110001110010101100011000"));
		System.out.println(setCardToWg26("6526348"));
	}
}
